<?php
	include "./sqlConnect.php";
	include "./timeHandle.php";
	include "./valuesHandling.php";
	include "./dataHandle.php";
	$os = substr(php_uname("s"), 0, 3);
	$sql = new SQLInterface($os);
//------------------------------------------------------------------------------
    function control($sql){
        $argV = func_get_args();
        $control 	= $argV[0]; //api control number
        $sqlIFace 	= $argV[1]; //sql interface instance

        //generate component address 
        $includePath = "./components/".$control.".php";

        //if component exist load it
        if (is_file($includePath)){
		    require_once($includePath);

		    //each control contains function 
		    //with following format: f(makes function name as string)
		    //and control number for example 200
		    //example is f200 or f210
		    $functionName = "f".$control;
			
			//if function name exist we execute it
			if (function_exists( $functionName)) {
				call_user_func($functionName, $sqlIFace);
	        }
		}
		else{			
			$temp = array();
			$temp['error'] = "API not programed";
			print(json_encode($temp));
		}
    }

	$request = $_GET['request'];
	
	
	include "./components/000.php";

	if($request == "000"){
		//Logon screen
		f000($sql);
	}
	
	if(verifyUser() == false){
		$temp = array();
		$temp['error'] = "401 Unauthorized";
		print(json_encode($temp));
		exit();
	}
	
//------------------------------------------------------------------------------
	$request = "";
	if(isset($_GET['request'])){

		$request = $_GET['request'];

    	control($request,$sql);
    	unset($sql);
    }
    else{
    	unset($sql);
    	exit();
    }
?>
